﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using GDFlacTool.Common;

namespace GDFlacTool.Forms
{
    public partial class FormSwapFieldText : Form
    {
        private readonly List<CopyFieldText> _dataSourceFrom = new List<CopyFieldText>();
        private readonly List<CopyFieldText> _dataSourceTo = new List<CopyFieldText>();
        private string _fromTagType = string.Empty;
        private string _fromPropertyName = string.Empty;
        private string _toTagType = string.Empty;
        private string _toPropertyName = string.Empty;

        public FormSwapFieldText()
        {
            InitializeComponent();

            Init();

            InitComboBoxes();
        }

        public string FromTagType
        {
            get { return _fromTagType; }
        }

        public string FromPropertyName
        {
            get { return _fromPropertyName; }
        }

        public string ToTagType
        {
            get { return _toTagType; }
        }

        public string ToPropertyName
        {
            get { return _toPropertyName; }
        }

        private void InitComboBoxes()
        {
            cboFrom.DataSource = _dataSourceFrom;
            cboFrom.DisplayMember = "Name";
            cboFrom.ValueMember = "Value";

            cboTo.DataSource = _dataSourceTo;
            cboTo.DisplayMember = "Name";
            cboTo.ValueMember = "Value"; 
        }

        private void Init()
        {
            _dataSourceFrom.Add(new CopyFieldText("Album", "Album", TagType.Album));
            _dataSourceFrom.Add(new CopyFieldText("Artist", "Artist", TagType.Artist));
            _dataSourceFrom.Add(new CopyFieldText("Album Artist", "Albumartist", TagType.Albumartist));
            _dataSourceFrom.Add(new CopyFieldText("Title", "Title", TagType.Title));
            _dataSourceFrom.Add(new CopyFieldText("Year", "Year", TagType.Year));
            _dataSourceFrom.Add(new CopyFieldText("Genre", "Genre", TagType.Genre));
            _dataSourceFrom.Add(new CopyFieldText("Comment", "Comment", TagType.Comment));
            _dataSourceFrom.Add(new CopyFieldText("Track Number", "TrackNumber", TagType.Tracknumber));
            _dataSourceFrom.Add(new CopyFieldText("Disc Number", "DiscNumber", TagType.Discnumber));
            _dataSourceFrom.Add(new CopyFieldText("Catalog", "Catalog", TagType.CatalogNumber));
            _dataSourceFrom.Add(new CopyFieldText("ISRC", "Isrc", TagType.Isrc));
            _dataSourceFrom.Add(new CopyFieldText("Release Type", "ReleaseType", TagType.ReleaseType));
            _dataSourceFrom.Add(new CopyFieldText("Composer", "Composer", TagType.Composer));
            _dataSourceFrom.Add(new CopyFieldText("Original Artist", "Originalartist", TagType.OriginalArtist));
            _dataSourceFrom.Add(new CopyFieldText("Copyright", "Copyright", TagType.Copyright));
            _dataSourceFrom.Add(new CopyFieldText("Url", "Url", TagType.Url));
            _dataSourceFrom.Add(new CopyFieldText("Encoded By", "EncodedBy", TagType.EncodedBy));
            _dataSourceFrom.Add(new CopyFieldText("Mood", "Mood", TagType.Mood));
            _dataSourceFrom.Add(new CopyFieldText("Rating", "Rating", TagType.Rating));
            _dataSourceFrom.Add(new CopyFieldText("Quality", "Quality", TagType.Quality));
            _dataSourceFrom.Add(new CopyFieldText("BPM", "Bpm", TagType.Bpm));
            _dataSourceFrom.Add(new CopyFieldText("Lyrics", "Lyrics", TagType.Lyrics));
            _dataSourceFrom.Add(new CopyFieldText("Conductor", "Conductor", TagType.Conductor));
            _dataSourceFrom.Add(new CopyFieldText("Lyricist", "Lyricist", TagType.Lyricist));
            _dataSourceFrom.Add(new CopyFieldText("Original Lyricist", "OriginalLyricist", TagType.OriginalLyricist));
            _dataSourceFrom.Add(new CopyFieldText("Label", "Label", TagType.Label));
            _dataSourceFrom.Add(new CopyFieldText("Remixed By", "RemixedBy", TagType.RemixedBy));
            _dataSourceFrom.Add(new CopyFieldText("Radio Station", "RadioStationName", TagType.RadioStationName));

            _dataSourceTo.Add(new CopyFieldText("Album", "Album", TagType.Album));
            _dataSourceTo.Add(new CopyFieldText("Artist", "Artist", TagType.Artist));
            _dataSourceTo.Add(new CopyFieldText("Album Artist", "Albumartist", TagType.Albumartist));
            _dataSourceTo.Add(new CopyFieldText("Title", "Title", TagType.Title));
            _dataSourceTo.Add(new CopyFieldText("Year", "Year", TagType.Year));
            _dataSourceTo.Add(new CopyFieldText("Genre", "Genre", TagType.Genre));
            _dataSourceTo.Add(new CopyFieldText("Comment", "Comment", TagType.Comment));
            _dataSourceTo.Add(new CopyFieldText("Track Number", "TrackNumber", TagType.Tracknumber));
            _dataSourceTo.Add(new CopyFieldText("Disc Number", "DiscNumber", TagType.Discnumber));
            _dataSourceTo.Add(new CopyFieldText("Catalog", "Catalog", TagType.CatalogNumber));
            _dataSourceTo.Add(new CopyFieldText("ISRC", "Isrc", TagType.Isrc));
            _dataSourceTo.Add(new CopyFieldText("Release Type", "ReleaseType", TagType.ReleaseType));
            _dataSourceTo.Add(new CopyFieldText("Composer", "Composer", TagType.Composer));
            _dataSourceTo.Add(new CopyFieldText("Original Artist", "Originalartist", TagType.OriginalArtist));
            _dataSourceTo.Add(new CopyFieldText("Copyright", "Copyright", TagType.Copyright));
            _dataSourceTo.Add(new CopyFieldText("Url", "Url", TagType.Url));
            _dataSourceTo.Add(new CopyFieldText("Encoded By", "EncodedBy", TagType.EncodedBy));
            _dataSourceTo.Add(new CopyFieldText("Mood", "Mood", TagType.Mood));
            _dataSourceTo.Add(new CopyFieldText("Rating", "Rating", TagType.Rating));
            _dataSourceTo.Add(new CopyFieldText("Quality", "Quality", TagType.Quality));
            _dataSourceTo.Add(new CopyFieldText("BPM", "Bpm", TagType.Bpm));
            _dataSourceTo.Add(new CopyFieldText("Lyrics", "Lyrics", TagType.Lyrics));
            _dataSourceTo.Add(new CopyFieldText("Conductor", "Conductor", TagType.Conductor));
            _dataSourceTo.Add(new CopyFieldText("Lyricist", "Lyricist", TagType.Lyricist));
            _dataSourceTo.Add(new CopyFieldText("Original Lyricist", "OriginalLyricist", TagType.OriginalLyricist));
            _dataSourceTo.Add(new CopyFieldText("Label", "Label", TagType.Label));
            _dataSourceTo.Add(new CopyFieldText("Remixed By", "RemixedBy", TagType.RemixedBy));
            _dataSourceTo.Add(new CopyFieldText("Radio Station", "RadioStationName", TagType.RadioStationName));
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            var from = (CopyFieldText) cboFrom.SelectedItem;
            var to = (CopyFieldText)cboTo.SelectedItem;

            _fromTagType = from.Type;
            _fromPropertyName = from.Value;
            _toTagType = to.Type;
            _toPropertyName = to.Value;
        }
    }
}
